import { loadJs } from '@/utils'
import { Ref } from 'vue'
export const minesResult = (
	gameContent: { appendChild: (arg0: HTMLDivElement) => void },
	details: any,
	loadingGameOut: Ref<boolean, boolean>
) => {
	loadingGameOut.value = true
	loadJs('/gameLib.js').then((originalGameLib: any) => {
		const mGameOut = new originalGameLib.MinesGameOut({
			onGameLoadEnd: () => {
				const resultDiv = document.createElement('div')
				resultDiv.style.cssText = 'width: 100%; height: 400px; background-color: #1B2538;'
				if (gameContent) {
					gameContent?.appendChild(resultDiv)
					resultDiv.appendChild(mGameOut.render())
					mGameOut.addGameResult(resultDiv.clientWidth, details.mines, details.filed)
					loadingGameOut.value = false
				}
			}
		})
	})
}

export const plinkoResult = (
	gameContent: { appendChild: (arg0: any) => void },
	details: { plinkoResult: any; rows: any; risk: string | number },
	loadingGameOut: Ref<boolean, boolean>
) => {
	loadingGameOut.value = true
	loadJs('/gameLib.js').then((originalGameLib: any) => {
		const mGameOut = new originalGameLib.PlinkoGameOut({
			onGameLoadEnd: () => {
				const resultDiv = document.createElement('div')
				resultDiv.style.cssText = 'background-color: #1B2538;'
				if (gameContent) {
					gameContent?.appendChild(resultDiv)
					resultDiv.appendChild(mGameOut.render())
					mGameOut.addGameResult(
						resultDiv.clientWidth,
						details.risk,
						details.rows,
						details.plinkoResult
					)
					loadingGameOut.value = false
				}
			}
		})
	})
}

export const diceResult = (
	gameContent: { appendChild: (arg0: any) => void },
	details: { condition: string; target: any; result: any },
	loadingGameOut: Ref<boolean, boolean>
) => {
	loadingGameOut.value = true
	loadJs('/gameLib.js').then((originalGameLib: any) => {
		const mGameOut = new originalGameLib.DiceGameOut({
			onGameLoadEnd: () => {
				const resultDiv = document.createElement('div')
				resultDiv.style.cssText = 'width: 100%; height: 300px; background-color: #1B2538;'
				if (gameContent) {
					gameContent?.appendChild(resultDiv)
					resultDiv.appendChild(mGameOut.render())
					mGameOut.addGameResult(
						resultDiv.clientWidth,
						details.condition === 'above',
						details.target,
						details.result
					)
					loadingGameOut.value = false
				}
			}
		})
	})
}

export const limboResult = (
	gameContent: { appendChild: (arg0: any) => void },
	details: { result: string; payout: any },
	loadingGameOut: Ref<boolean, boolean>
) => {
	loadingGameOut.value = true
	loadJs('/gameLib.js').then((originalGameLib: any) => {
		const mGameOut = new originalGameLib.LimboGameOut({
			onGameLoadEnd: () => {
				const resultDiv = document.createElement('div')
				resultDiv.style.cssText = 'background-color: #1B2538;'
				if (gameContent) {
					gameContent?.appendChild(resultDiv)
					resultDiv.appendChild(mGameOut.render())
					mGameOut.addGameResult(resultDiv.clientWidth, details.result, details.payout)
					loadingGameOut.value = false
				}
			}
		})
	})
}

export const kenoResult = (
	gameContent: { appendChild: (arg0: any) => void },
	details: { risk: any; result: any },
	loadingGameOut: Ref<boolean, boolean>
) => {
	loadingGameOut.value = true
	loadJs('/gameLib.js').then((originalGameLib: any) => {
		const KenoRiskLevel = originalGameLib.KenoRiskLevel
		const mGameOut = new originalGameLib.KenoGameOut({
			onGameLoadEnd: () => {
				const resultDiv = document.createElement('div')
				resultDiv.style.cssText = 'width: 100%; height: 240px; background-color: #1B2538;'
				if (gameContent) {
					gameContent?.appendChild(resultDiv)
					resultDiv.appendChild(mGameOut.render())
					mGameOut.addGameResult(resultDiv.clientWidth, KenoRiskLevel[details.risk], details.result)
					loadingGameOut.value = false
				}
			}
		})
	})
}

export const wheelResult = (
	gameContent: { appendChild: (arg0: any) => void },
	details: { risk: any; segments: any; result: any },
	loadingGameOut: Ref<boolean, boolean>
) => {
	loadingGameOut.value = true
	loadJs('/gameLib.js').then((originalGameLib: any) => {
		const mWheelGameOut = new originalGameLib.WheelGameOut({
			onGameLoadEnd: () => {
				const resultDiv = document.createElement('div')
				resultDiv.style.cssText = 'width: 300px; height: 350px; background-color: #1B2538;'
				if (gameContent) {
					gameContent?.appendChild(resultDiv)
					resultDiv.appendChild(mWheelGameOut.render())
					mWheelGameOut.addGameResult(
						resultDiv.clientWidth,
						details.risk,
						details.segments,
						details.result
					)
					loadingGameOut.value = false
				}
			}
		})
	})
}
